package com.sushi.active;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;

@Component
@Aspect
public class AopActive {

    @Pointcut("execution(void com.sushi.service.AopService.m1())")
    public void cutPoint(){}


    @Pointcut("execution(void com.sushi.service.AopService.throwTry())")
    public void throwing(){}
    @AfterThrowing(value = "throwing()", throwing = "obj")
    public void throwOut(Throwable obj) {
        System.out.println("抛出了异常");
    }

    @Pointcut("execution(* com.sushi.service.AopService.returnTry())")
    public void rtt(){}
    @AfterReturning(value = "rtt()", returning = "arr")
    public Object returning(ArrayList<Integer> arr) throws Throwable {
        System.out.println("切面返回");
        return arr;
    }
    @Around("rtt()")
    public Object vvvv(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("前置");
//        ArrayList<Integer> proceed = (ArrayList<Integer>)pjp.proceed();
        Object proceed = pjp.proceed();
        System.out.println("后置");
        return proceed;
    }

//    @After("cutPoint()")
    //@Before("cutPoint()")
    public void show() {
        System.out.println("当前时间" + new Date());
    }
    @Pointcut("execution(void com.sushi.service.PersonService.m1())")
    public void pt(){}
    @Before("pt()")
    public void m2(){
        System.out.println("2222222222222");
    }

}
